package com.gw.smscheck.service.sys.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gw.smscheck.dao.sys.LoginUserMapper;
import com.gw.smscheck.entity.sys.LoginUser;
import com.gw.smscheck.service.sys.LoginUserService;
import com.gw.smscheck.util.ResultObj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 登录用户业务层实现类
 * @Author: JunYaoWang
 * @Data: Created in 15:51 2018/11/14
 */
@Service
public class LoginUserServiceImpl implements LoginUserService{
    @Autowired
    private LoginUserMapper loginUserMapper;
    /**
     * 分页查询
     * @param dto
     * @return
     */
    @Override
    public PageInfo<LoginUser> pageSelect(LoginUser dto) {
        PageHelper.startPage(dto.getPage(), dto.getRows(), "login_name desc");// 排序
        List<LoginUser> resultList = loginUserMapper.pageSelect(dto);
        PageInfo<LoginUser> pageInfo = new PageInfo<>(resultList);
        return pageInfo;
    }

    /**
     *  添加
     * @param user
     * @return
     */
    @Override
    public ResultObj add(LoginUser user) {
        ResultObj resultObj = new ResultObj();
        //判断两次输入的密码是否正确
        if(!user.getPassword().equals(user.getVerifyPassword())){
            resultObj.setCode(ResultObj.CODE_FAIL);
            resultObj.setMsg("两次输入的密码不同");
            return resultObj;
        }
        loginUserMapper.add(user);
        resultObj.setCode(ResultObj.CODE_SUCCESS);
        resultObj.setMsg("保存成功");
        return resultObj;
    }

    /**
     * 修改
     * @param user
     * @return
     */
    @Override
    public Integer update(LoginUser user) {
        return loginUserMapper.update(user);
    }

    /**
     * 根据id查询
     * @param user
     * @return
     */
    @Override
    public LoginUser findById(LoginUser user) {
        return loginUserMapper.findById(user);
    }

    /**
     * 根据id删除
     * @param user
     * @return
     */
    @Override
    public Integer delete(LoginUser user) {
        return loginUserMapper.delete(user);
    }
}
